package com.taylor.spring5.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/**
 * @author taylor
 * @Description: TODO
 * @date 2021/4/4 23:32
 */
@Component
@Aspect
@Order(2)
public class UserProxy {


    @Pointcut(value = "execution(* com.taylor.spring5.aop.*.*(..))")
    public void pointCut(){

        System.out.println("抽取相同切入点");
    }
    /**
     * 前置通知
     */
    @Before(value = "pointCut()")
    public void before() {
        System. out .println( "before......");
    }
    /**
     * 最终通知
     */
    @After(value = "pointCut()")
    public void after() {
        System. out .println( "after......");
    }
    /**
     * 返回通知
     */
    @AfterReturning(value = "pointCut()")
    public void afterReturning() {
        System. out .println( "afterReturning......");
    }

    /**
     * 异常通知
     */
    @AfterThrowing(value = "pointCut()")
    public void afterThrowing() {
        System. out .println( "afterThrowing......");
    }

    /**
     * 环绕通知
     */
    @Around(value = "pointCut()")
    public void around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable { //前置通知
        System. out .println( "环绕之前......");
        Object proceed = proceedingJoinPoint.proceed();
        System. out .println( "环绕之后......");

    }
}
